<template>
  <!-- 所属从业人员 -->
  <div class="app-container">
    <el-form v-show="showSearch" ref="queryForm" :inline="true" :model="queryParams" label-width="auto" size="small">
      <el-form-item label="更新时间" prop="releaseTime">
        <el-date-picker
          v-model="dateRange"
          end-placeholder="结束日期"
          range-separator="-"
          start-placeholder="开始日期"
          style="width: 240px"
          type="daterange"
          value-format="yyyy-MM-dd"
        />
      </el-form-item>
      <el-form-item label="性别" prop="sex">
        <el-select v-model="queryParams.sex" clearable placeholder="请选择性别">
          <el-option
            v-for="dict in dict.type.bhxq_employee_sex"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="从业状态" prop="practiceStatus">
        <el-select v-model="queryParams.practiceStatus" clearable placeholder="请选择从业状态">
          <el-option
            v-for="dict in dict.type.bhxq_employee_practice_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="姓名" prop="name">
        <el-input
          v-model="queryParams.name"
          clearable
          placeholder="请输入姓名"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="联系电话" prop="phone">
        <el-input
          v-model="queryParams.phone"
          maxlength="11"
          clearable
          placeholder="请输入联系电话"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button icon="el-icon-search" size="mini" type="primary" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          v-hasPermi="['system:employee:add']"
          icon="el-icon-plus"
          plain
          size="mini"
          type="primary"
          @click="handleAdd"
        >新增
        </el-button>
      </el-col>
      <!--<el-col :span="1.5">
        <el-upload
            class="upload-demo"
            style="float: right"
            :show-file-list="false"
        >
          <el-button size="mini" icon="el-icon-download" plain type="warning">导入</el-button>
        </el-upload>
      </el-col>-->
      <right-toolbar :show-search.sync="showSearch" @queryTable="getList" />
    </el-row>
    <el-table v-loading="loading" :data="employeeList" @selection-change="handleSelectionChange">
      <el-table-column align="center" label="更新时间" prop="updateTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.updateTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="姓名" prop="name" />
      <el-table-column align="center" label="性别" prop="sex">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.bhxq_employee_sex" :value="scope.row.sex" />
        </template>
      </el-table-column>
      <el-table-column align="center" label="从业状态" prop="practiceStatus">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.bhxq_employee_practice_status" :value="scope.row.practiceStatus" />
        </template>
      </el-table-column>
      <el-table-column align="center" label="人员资质信息" prop="aptitudeCount">
        <template slot-scope="scope">
          {{ scope.row.aptitudeCount + '条' }}
        </template>
      </el-table-column>
      <el-table-column align="center" label="人员培训信息" prop="trainCount">
        <template slot-scope="scope">
          {{ scope.row.trainCount + '条' }}
        </template>
      </el-table-column>
      <el-table-column align="center" label="人员事故信息" prop="accidentCount">
        <template slot-scope="scope">
          {{ scope.row.accidentCount + '条' }}
        </template>
      </el-table-column>
      <el-table-column align="center" label="联系方式" prop="phone" />
      <el-table-column align="center" class-name="small-padding fixed-width" label="操作">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            @click="handleexamine(scope.row)"
          >查看
          </el-button>
          <el-button
            size="mini"
            type="text"
            @click="handleUpdate(scope.row)"
          >修改
          </el-button>
          <el-button
            size="mini"
            type="text"
            @click="handleDelete(scope.row)"
          >删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :limit.sync="queryParams.pageSize"
      :page.sync="queryParams.pageNum"
      :total="total"
      @pagination="getList"
    />

    <!-- 添加或修改人员信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" append-to-body width="70%">
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-row>
          <el-col :span="8">
            <el-form-item label="姓名" prop="name">
              <el-input v-model="form.name" :disabled="disabledon" placeholder="请输入姓名" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="性别" prop="sex">
              <el-select v-model="form.sex" :disabled="disabledon" placeholder="请选择性别">
                <el-option
                  v-for="dict in dict.type.bhxq_employee_sex"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="联系电话" prop="phone">
              <el-input
                v-model="form.phone"
                :disabled="disabledon"
                maxlength="11"
                placeholder="请输入联系电话"
              />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <el-form-item label="出生日期" prop="birthday">
              <el-date-picker
                v-model="form.birthday"
                :disabled="disabledon"
                type="date"
                placeholder="选择日期"
                value-format="yyyy-MM-dd"
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="国籍" prop="nationality">
              <el-input v-model="form.nationality" :disabled="disabledon" placeholder="请输入国籍" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="籍贯" prop="nativePlace">
              <el-input v-model="form.nativePlace" :disabled="disabledon" placeholder="请输入籍贯" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="8">
            <el-form-item label="城市" prop="city">
              <el-input v-model="form.city" :disabled="disabledon" placeholder="请输入城市" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="街道" prop="street">
              <el-input v-model="form.street" :disabled="disabledon" placeholder="请输入街道" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="居住住址" prop="liveAddr">
              <el-input v-model="form.liveAddr" :disabled="disabledon" placeholder="请输入居住住址" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="8">
            <el-form-item label="从业状态" prop="practiceStatus">
              <el-select v-model="form.practiceStatus" :disabled="disabledon" placeholder="请选择从业状态">
                <el-option
                  v-for="dict in dict.type.bhxq_employee_practice_status"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="证件类型" prop="certType">
              <el-select v-model="form.certType" :disabled="disabledon" placeholder="请选择证件类型">
                <el-option
                  v-for="dict in dict.type.bhxq_employee_cert_type"
                  :key="dict.value"
                  :label="dict.label"
                  :value="dict.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="证件编号" prop="certCode">
              <el-input v-model="form.certCode" :disabled="disabledon" placeholder="请输入证件编号" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="8">
            <el-form-item label="管理机关" prop="managerOrg">
              <el-input v-model="form.managerOrg" :disabled="disabledon" placeholder="请输入管理机关" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="岗位名称" prop="postName">
              <el-input v-model="form.postName" :disabled="disabledon" placeholder="请输入岗位名称" />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="职务名称" prop="dutiesName">
              <el-input v-model="form.dutiesName" :disabled="disabledon" placeholder="请输入职务名称" />
            </el-form-item>
          </el-col>
        </el-row>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button v-if="disabledon == false" v-no-more-click type="primary" @click="submitForm">确 定</el-button>
        <el-button v-if="disabledon == false && title !== '修改人员信息'" type="primary" @click="submitForm('ContinueFill')">确定并继续填写</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
// import { listEmployee, getEmployee, delEmployee, addEmployee, updateEmployee } from '@/api/bhxq/employee'
// import { getEnterprise } from '../../../api/bhxq/passengervehicleinformation'

import { addEmployee, delEmployee, getEmployee, listEmployee, updateEmployee } from '@/api/informationReport'

export default {
  name: 'Index',
  dicts: ['bhxq_employee_sex', 'bhxq_employee_cert_type', 'bhxq_employee_practice_cert_type', 'bhxq_employee_practice_status', 'bhxq_employee_post_status'],
  data() {
    return {
      // 日期范围
      dateRange: [],
      disabledon: true,
      // 企业列表
      enterprise: [],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 人员信息表格数据
      employeeList: [{}],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        enterpriseId: null,
        businessType: null,
        name: null,
        sex: null,
        phone: null,
        mail: null,
        birthday: null,
        nationality: null,
        nativePlace: null,
        city: null,
        street: null,
        liveAddr: null,
        workUnit: null,
        workAddr: null,
        certType: null,
        certCode: null,
        uniteCreditCode: null,
        practiceCertType: null,
        practiceCertNum: null,
        firstDate: null,
        currentsDate: null,
        deadlineDate: null,
        practiceCertOrg: null,
        managerOrg: null,
        postName: null,
        dutiesName: null,
        practiceStatus: null,
        postStatus: null
      },
      queryParamslist: {
        enterpriseId: null,
        businessType: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        enterpriseId: [
          { required: true, message: '企业ID不能为空', trigger: 'change' }
        ],
        businessType: [
          { required: true, message: '类型不能为空', trigger: 'change' }
        ],
        name: [
          { required: true, message: '姓名不能为空', trigger: 'blur' }
        ],
        sex: [
          { required: true, message: '性别不能为空', trigger: 'change' }
        ],
        birthday: [
          { required: true, message: '出生日期不能为空', trigger: 'change' }
        ],
        phone: [
          { required: true, message: '联系电话不能为空', trigger: 'blur' },
          {
            pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
            message: '请输入正确的手机号码',
            trigger: 'blur'
          }
        ],
        mail: [
          { required: true, message: '联系邮箱不能为空', trigger: 'blur' },
          {
            type: 'email',
            message: '请输入正确的邮箱地址',
            trigger: ['blur', 'change']
          }
        ],
        // birthday: [
        //   { required: true, message: '出生日期不能为空', trigger: 'blur' }
        // ],
        nationality: [
          { required: true, message: '国籍不能为空', trigger: 'blur' }
        ],
        nativePlace: [
          { required: true, message: '籍贯不能为空', trigger: 'blur' }
        ],
        city: [
          { required: true, message: '城市不能为空', trigger: 'blur' }
        ],
        street: [
          { required: true, message: '街道不能为空', trigger: 'blur' }
        ],
        liveAddr: [
          { required: true, message: '居住住址不能为空', trigger: 'blur' }
        ],
        workUnit: [
          { required: true, message: '工作单位不能为空', trigger: 'blur' }
        ],
        workAddr: [
          { required: true, message: '工作地址不能为空', trigger: 'blur' }
        ],
        certType: [
          { required: true, message: '证件类型不能为空', trigger: 'change' }
        ],
        certCode: [
          { required: true, message: '证件编号不能为空', trigger: 'blur' }
        ],
        uniteCreditCode: [
          { required: true, message: '统一信用代码不能为空', trigger: 'blur' }
        ],
        practiceCertType: [
          { required: true, message: '从业证件类型不能为空', trigger: 'change' }
        ],
        practiceCertNum: [
          { required: true, message: '从业资格证编号不能为空', trigger: 'blur' }
        ],
        firstDate: [
          { required: true, message: '初次发证日期YYYY-MM-DD不能为空', trigger: 'blur' }
        ],
        currentsDate: [
          { required: true, message: '本次发证日期YYYY-MM-DD不能为空', trigger: 'blur' }
        ],
        deadlineDate: [
          { required: true, message: '有效截至日期YYYY-MM-DD不能为空', trigger: 'blur' }
        ],
        practiceCertOrg: [
          { required: true, message: '从业证发证机构不能为空', trigger: 'blur' }
        ],
        managerOrg: [
          { required: true, message: '管理机关不能为空', trigger: 'blur' }
        ],
        postName: [
          { required: true, message: '岗位名称不能为空', trigger: 'blur' }
        ],
        dutiesName: [
          { required: true, message: '职务名称不能为空', trigger: 'blur' }
        ],
        practiceStatus: [
          { required: true, message: '从业状态不能为空', trigger: 'change' }
        ],
        postStatus: [
          { required: true, message: '证件当前状态不能为空', trigger: 'change' }
        ]
      }
    }
  },
  created() {
    this.getList()
    // this.getEnterpriselist()
  },
  methods: {
    // 查询企业列表
    // getEnterpriselist() {
    //   this.queryParamslist.businessType = 1
    //   getEnterprise(this.queryParamslist).then(response => {
    //     console.log(response.data)
    //     this.enterprise = response.data
    //   })
    // },
    /** 查询人员信息列表 */
    getList() {
      if (this.dateRange == null) {
        this.dateRange = []
      }
      this.loading = true
      const data = {
        name: this.queryParams.name,
        phone: this.queryParams.phone,
        updateTimeStart: this.dateRange.length === 0 ? undefined : this.dateRange[0],
        updateTimeEnd: this.dateRange.length === 0 ? undefined : this.dateRange[1],
        practiceStatus: this.queryParams.practiceStatus,
        sex: this.queryParams.sex,
        pageNum: this.queryParams.pageNum,
        pageSize: this.queryParams.pageSize
      }
      this.queryParams.businessType = 1
      listEmployee(data).then(response => {
        this.employeeList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        employeeId: null,
        enterpriseId: null,
        businessType: null,
        name: null,
        sex: null,
        phone: null,
        mail: null,
        birthday: null,
        nationality: null,
        nativePlace: null,
        city: null,
        street: null,
        liveAddr: null,
        workUnit: null,
        workAddr: null,
        certType: null,
        certCode: null,
        uniteCreditCode: null,
        practiceCertType: null,
        practiceCertNum: null,
        firstDate: null,
        currentsDate: null,
        deadlineDate: null,
        practiceCertOrg: null,
        managerOrg: null,
        postName: null,
        dutiesName: null,
        practiceStatus: null,
        postStatus: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        delFlag: null
      }

      this.resetForm('form')
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.dateRange = []
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.employeeId)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset()
      this.disabledon = false
      this.open = true
      this.title = '新增从业人员'
    },

    /** 查看按钮操作 */
    handleexamine(row) {
      // this.reset()
      // const employeeId = row.employeeId || this.ids
      // getEmployee(employeeId).then(response => {
      //   this.form = response.data
      // console.log('row', row)
      this.reset()
      this.form = JSON.parse(JSON.stringify(row))
      this.disabledon = true
      this.open = true
      this.title = '查看人员信息'
      // })
    },

    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset()
      // const employeeId = row.employeeId || this.ids
      getEmployee(row.employeeId).then(response => {
        this.form = response.data
        this.disabledon = false
        this.open = true
        this.title = '修改人员信息'
      })
    },
    /** 提交按钮 */
    submitForm(type) {
      this.$refs['form'].validate(valid => {
        if (valid) {
          if (this.form.employeeId != null) {
            this.form.businessType = 1
            updateEmployee(this.form).then(response => {
              this.$modal.msgSuccess('修改成功')
              this.open = false
              this.getList()
            })
          } else {
            this.form.businessType = 1
            addEmployee(this.form).then(response => {
              this.$modal.msgSuccess('新增成功')
              // 当点击确认确定并继续填写时 模态框不关闭
              if (type === 'ContinueFill') {
                this.reset()
                this.open = true
              } else {
                this.open = false
              }
              this.getList()
            })
          }
        }
      })
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      // const employeeIds = row.employeeId || this.ids
      this.$modal.confirm('是否删除姓名为"' + row.name + '"人员全部信息？').then(function() {
        return delEmployee(row.employeeId)
      }).then(() => {
        this.getList()
        this.$modal.msgSuccess('删除成功')
      }).catch(() => {
      })
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('background/bhxqEmployee/export', {
        ...this.queryParams
      }, `employee_${new Date().getTime()}.xlsx`)
    }
  }
}
</script>
<style>
.el-checkbox__input.is-disabled + .el-checkbox__label {
  color: #606266 !important;
}

.el-checkbox__input.is-disabled.is-checked + .el-checkbox__label {
  color: #606266 !important;
}

.el-checkbox__input.is-disabled.is-checked .el-checkbox__inner:after {
  border-color: #606266 !important;
}

.el-radio__input.is-disabled + span.el-radio__label {
  color: #606266 !important;
}

.el-radio__input.is-disabled.is-checked .el-radio__inner::after {
  background-color: #606266 !important;
}

.el-radio__input.is-disabled .el-radio__inner, .el-radio__input.is-disabled.is-checked .el-radio__inner {
  border-color: #606266 !important;
}

.el-input.is-disabled .el-input__inner, textarea:disabled {
  color: #606266 !important;
}

.el-range-editor.is-disabled input {
  color: #606266 !important;
}

.el-tooltip__popper {

  max-width: 20%;

}

.el-tooltip__popper, .el-tooltip__popper.is-dark {

  background: rgb(48, 65, 86) !important;

  color: #fff !important;

  line-height: 24px;

}
</style>
<style scoped>
.el-date-editor.el-input, .el-date-editor.el-input__inner {
  width: 100%;
}
.el-select {
  display: inline-block;
  position: relative;
  width: 100%;
}
</style>
